<?php
error_reporting(0);
ini_set('memory_limit', '1000M');
set_time_limit(0);


/** 
 *  mapper7.php
 *      input:格式：mapred7输出 (json1\tjson2\t...)尤其要注意其中的weight字段
 *      handle:生成sql
 *      output:sql语句--INSERT INTO `house_sell_del` VALUES ('1', ...);
 * @created 2016-03-09
 * @by delia
 */
$nu=0;
while (($line_json = fgets(STDIN)) !== false) {   //line_json=>source_url\tjson格式
    if($nu==0){
	echo "INSERT INTO house_del_gov(id,broker_id,house_price,house_desc,house_title,cityarea_id, cityarea2_id,house_floor,house_topfloor,house_toward,house_room,house_hall,house_toilet,house_kitchen,house_fitment,house_feature,house_built_year,use_area,owner_name,owner_phone,service_phone,house_support,created,updated,status,source,company_id,source_owner,app_url,wap_url,source_url,is_checked,click_num,refresh,house_type,house_totalarea,borough_id,borough_name,house_pic_unit,house_pic_layout,house_number,is_fill,is_contrast,public_time,source_name,off_type,vr_url,video_url,tag) VALUES";
        $nu=1;
    }        
    else{
	echo ",\n";
        $nu+=1;
    }
    $line_json = trim($line_json);
    list($suffix, $line_json) = explode("\t", $line_json);
    if (empty($line_json))
        continue;
    $one_dejson=json_decode($line_json,true); 
    echo " ('".$one_dejson['id']."','"
	.$one_dejson['broker_id']."','".$one_dejson['house_price']."','".
	str_replace("'","",str_replace("\\","",$one_dejson['house_desc']))."','".
	str_replace("'","",str_replace("\\","",$one_dejson['house_title']))."','".
	$one_dejson['cityarea_id']."','".$one_dejson['cityarea2_id']."','".
	$one_dejson['house_floor']."','".$one_dejson['house_topfloor']."','".
	$one_dejson['house_toward']."','".$one_dejson['house_room']."','".
	$one_dejson['house_hall']."','".$one_dejson['house_toilet']."','".
	$one_dejson['house_kitchen']."','".$one_dejson['house_fitment']."','".
	str_replace("'","",$one_dejson['house_feature'])."','".
	str_replace("'","",$one_dejson['house_built_year'])."','".
	$one_dejson['use_area']."','".
	str_replace("'","",$one_dejson['owner_name'])."','".
	$one_dejson['owner_phone']."','".
	$one_dejson['service_phone']."','".$one_dejson['house_support']."','".
	$one_dejson['created']."','".$one_dejson['updated']."','".
	$one_dejson['status']."','".$one_dejson['source']."','".
    $one_dejson['company_id']."','".
    #"0"."','".
	$one_dejson['source_owner']."','".$one_dejson['app_url']."','".
	$one_dejson['wap_url']."','".$one_dejson['source_url']."','".
	$one_dejson['is_checked']."','".$one_dejson['click_num']."','".
	$one_dejson['refresh']."','".$one_dejson['house_type']."','".
	$one_dejson['house_totalarea']."','".$one_dejson['borough_id']."','".
	$one_dejson['borough_name']."','".$one_dejson['house_pic_unit']."','".
	$one_dejson['house_pic_layout']."','".$one_dejson['house_number']."','".
	$one_dejson['is_fill']."','".$is_contrast."','".
	$one_dejson['public_time']."','".$one_dejson['source_name']."','".
	$one_dejson['off_type']."','".$one_dejson['vr_url']."','".$one_dejson['video_url']."','".
    $one_dejson['tag']."')";
	if($nu==19){
            echo ";\n";
            $nu=0;
        }

}
echo ";\n";	
?>

